Skip to content

Add caching rules for immutable files in web.config#158

Open
turbobobbytraykov wants to merge 2 commits intovnextfrom
btraykov/implement-iis-caching-optimizations
Open

Add caching rules for immutable files in web.config#158
turbobobbytraykov wants to merge 2 commits intovnextfrom
btraykov/implement-iis-caching-optimizations

Conversation

@turbobobbytraykov
Copy link
Contributor

Added outbound rules for caching immutable files and defined preconditions for specific file patterns.
Based on the changes that Pablo introduced in IgniteUI/igniteui-angular-samples#3879 for the other Angular samples

Why:
SPA had a 1 year cache for all static files, including the index.html
This is terribly bad for updating the app because you get an older version of the app unless you force reload.
This can also lead to crashes, because the cached index.html will reference related scripts that are no longer there.

How:

  • New rules:
    • index.html 5 min public cache
    • Hashed files 1 year immutable public cache
      • main-<hash>.js
      • chunk-<hash>.js
      • polyfills-<hash>.js
      • styles-<hash>.css
  • Other static assets 1 hour

Additionally:

  • Enable SVG compression

These changes are already applied to

After testing this, the same approach should be applied to angular-grid-examples as well

@turbobobbytraykov
Copy link
Contributor Author

@pmoleri , you can check the grid examples at: https://staging.infragistics.com/angular-grid-examples/home/sales

I think everything is working as intended now.

@pmoleri
Copy link

pmoleri commented Feb 19, 2026

No, it's not working correctly.
Main HTML file should be only 5 min cache
image

Comment on lines +38 to +47
</rule>
<preConditions>
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
<add input="{REQUEST_URI}" pattern="/media/.*" />
</preCondition>
</preConditions>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is a Server Side Rendered app and the index.html cache rule doesn't work in this case.

We can add the following rule to match all 200 HTML pages.

Suggested change
</rule>
<preConditions>
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
<add input="{REQUEST_URI}" pattern="/media/.*" />
</preCondition>
</preConditions>
</rule>
<rule name="Cache SSR HTML pages" preCondition="IsHTMLResponse">
<match serverVariable="RESPONSE_Cache-Control" pattern=".*" />
<action type="Rewrite" value="public, max-age=300" />
</rule>
<preConditions>
<preCondition name="IsImmutable" logicalGrouping="MatchAny">
<add input="{REQUEST_URI}" pattern="styles-.*\.css$" />
<add input="{REQUEST_URI}" pattern="chunk-.*\.js$" />
<add input="{REQUEST_URI}" pattern="main-.*\.js$" />
<add input="{REQUEST_URI}" pattern="polyfills-.*\.js$" />
<add input="{REQUEST_URI}" pattern="/media/.*" />
</preCondition>
<preCondition name="IsHTMLResponse" logicalGrouping="MatchAll">
<add input="{RESPONSE_STATUS}" pattern="^200$" />
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants